//---------------------------------------------------------------------------

#include "vcl_stl.h"
#pragma hdrstop

#include "h_base.h"
#include "h_xml.h"
using namespace h_base;
using namespace h_xml;

#include "h_global.h"
#include "h_designcontrol.h"
#include "h_stage.h"
#include "t_mainform.h"
#include "t_dummyform.h"

#include "t_batform.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TBatForm *BatForm;
//---------------------------------------------------------------------------
__fastcall TBatForm::TBatForm(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TBatForm::ButtonOkClick(TObject *Sender)
{
   UTF8String ErrorString;

   Info.GroupName = EditGroupName->Text.UpperCase().TrimRight();
   Info.Author = EditAuthor->Text.TrimRight();
   Info.JobTrigger = EditJobTrigger->Text.TrimRight();
   Info.BatchTrigger = EditBatchTrigger->Text.TrimRight();
   Info.AutoSkip = CheckBoxAutoSkip->Checked;
   Info.AutoRerun = EditAutoRerun->Text.TrimRight();
   Info.Description = GetStringFromMemo(MemoDescription);
   Info.IncludeFiles = GetStringFromMemo(MemoIncludeFiles);
   Info.CheckBeforeTransfer = CheckBoxCheckBeforeTransfer->Checked;
   Info.FadingPeriod = EditFadingPeriod->Text.TrimRight();
   Info.PartitionDither = EditPartitionDither->Text.TrimRight();
   Info.SectionList = EditSectionList->Text.UpperCase().TrimRight();
   Info.AcrossDayEnd = CheckBoxAcrossDayEnd->Checked;
   Info.Banner = EditBanner->Text;
   Info.BannerPosition = ComboBoxBannerPosition->ItemIndex;
   Info.BannerFontName = FontDialog1->Font->Name;
   Info.BannerFontSize = FontDialog1->Font->Size;
   FontStyleToInt(Info.BannerFontStyle, FontDialog1->Font->Style);
   Info.TrafficControl = EditTrafficControl->Text.TrimRight();

   if( !MainForm->SetInfo(Info, ErrorString) )
   {
      ShowMessage(ErrorString);
      return;
   }

   OkFlag = true;
   Close();
}
//---------------------------------------------------------------------------

void __fastcall TBatForm::ButtonCancelClick(TObject *Sender)
{
   Close();
}
//---------------------------------------------------------------------------

bool __fastcall TBatForm::Edit(void)
{
   MainForm->GetInfo(Info);
   UTF8String Cap;
   Cap.sprintf(UTF8String(DummyForm->PropertiesOf->Caption).c_str(), "batch");
   Caption = Cap;

   EditGroupName->Text = Info.GroupName;

   if( Info.Author == "" )
   {
      wchar_t TmpStr[201];
      unsigned long Size = 200;
      if( GetUserName(TmpStr, &Size) )
         EditAuthor->Text = TmpStr;
   }
   else
      EditAuthor->Text = Info.Author;

   EditJobTrigger->Text = Info.JobTrigger;
   EditBatchTrigger->Text = Info.BatchTrigger;
   CheckBoxAutoSkip->Checked = Info.AutoSkip;
   EditAutoRerun->Text = Info.AutoRerun;
   SetStringToMemo(MemoDescription, Info.Description);
   SetStringToMemo(MemoIncludeFiles, Info.IncludeFiles);
   CheckBoxCheckBeforeTransfer->Checked = Info.CheckBeforeTransfer;
   EditFadingPeriod->Text = Info.FadingPeriod;
   EditPartitionDither->Text = Info.PartitionDither;
   EditSectionList->Text = Info.SectionList;
   CheckBoxAcrossDayEnd->Checked = Info.AcrossDayEnd;
   EditBanner->Text = Info.Banner;
   ComboBoxBannerPosition->ItemIndex = Info.BannerPosition;
   EditBannerFontName->Text = Info.BannerFontName;
   FontDialog1->Font->Name = Info.BannerFontName;
   FontDialog1->Font->Size = Info.BannerFontSize;
   Set<TFontStyle, fsBold, fsStrikeOut> FontStyle;
   IntToFontStyle(Info.BannerFontStyle, FontStyle);
   FontDialog1->Font->Style = FontStyle;
   EditTrafficControl->Text = Info.TrafficControl;
   OkFlag = false;
   PageControl1->ActivePageIndex = 0;
   ShowModal();

   if( !OkFlag )
      return false;

   MainForm->CurrentDesignControl()->Invalidate();
   return true;
}
void __fastcall TBatForm::ButtonChangeClick(TObject *Sender)
{
   FontDialog1->Execute();
   EditBannerFontName->Text = FontDialog1->Font->Name;
}
//---------------------------------------------------------------------------

